/**
 * 亿牛集团
 * 本源代码由亿牛集团及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2017 yiniu.com all rights reserved.
 */

package com.rico.simplejdbc.jdbc06.web;

import com.rico.simplejdbc.jdbc06.form.UserForm;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.http.HTTPException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

/**
 * @author yaoyongfeng
 */
@RestController
@RequestMapping(path = "/site")
public class SiteController {
    @ResponseBody
    @RequestMapping(path = "/index")
    public void index(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
        PrintWriter writer = httpServletResponse.getWriter();
        writer.write(httpServletRequest.getMethod() == null ? "" : httpServletRequest.getMethod());
        writer.write(httpServletRequest.getQueryString() == null ? "" : httpServletRequest.getQueryString());
        Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
        String header;
        while (headerNames.hasMoreElements()) {
            header = headerNames.nextElement();
            writer.println(header + ":" + httpServletRequest.getHeader(header));
        }
//        httpServletRequest.getParameterMap().entrySet()
        writer.println(httpServletRequest.getParameterMap());
    }

    @RequestMapping(path = "/test")
    @ResponseBody
    public String doPost(@ModelAttribute(name = "test") UserForm userForm) {
        return userForm.toString();
    }


}
